package com.maxus.mini.data.provider;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.maux.mini.data.api.BaseService;
import com.maxus.mini.common.VersionedAuditableIdEntity;
import com.maxus.mini.repository.BaseRepository;

/**
 * 用户管理
 * 
 * @author wujinsong
 *
 */
@Component()
@Service(version = "1.0.0")
public abstract class BaseServiceImpl<T extends VersionedAuditableIdEntity, ID extends Serializable>
		implements BaseService<T, ID> {
	@Autowired
	private BaseRepository<T> baseRepository;

	@Override
	public long count() {
		return baseRepository.count();
	}

	@Override
	public <S extends T> Iterable<S> save(Iterable<S> entities) {
		return baseRepository.save(entities);
	}

	@Override
	public <S extends T> S save(S entity) {
		return baseRepository.save(entity);
	}

	@Override
	public T find(Long id) {
		return baseRepository.findOne(id);
	}

	@Override
	public boolean exists(Long id) {
		return baseRepository.exists(id);
	}

	@Override
	public void delete(Long id) {
		baseRepository.delete(id);
	}

	@Override
	public void delete(T entity) {
		baseRepository.delete(entity);
	}

	@Override
	public <S extends T> void delete(Iterable<S> entities) {
		baseRepository.delete(entities);
	}

	@Override
	public void deleteAll() {
		baseRepository.deleteAll();
	}

	@Override
	public Iterable<T> findAll() {
		return baseRepository.findAll();
	}

	@Override
	public Iterable<T> findAll(Iterable<Long> ids) {
		return baseRepository.findAll(ids);
	}

	@Override
	public Iterable<T> findAll(Sort sort) {
		return baseRepository.findAll(sort);
	}

	@Override
	public Page<T> findAll(Pageable pageable) {
		return baseRepository.findAll(pageable);
	}
}
